import cv2
import numpy as np
from PIL import Image, ImageDraw, ImageFont

img = np.zeros((400,400,3),dtype="uint8")
cv2.putText(img,'OpenCV',(20,150), cv2.FONT_HERSHEY_SIMPLEX, 2,(128,0,0),15)
cv2.putText(img,'OpenCV',(20,150), cv2.FONT_HERSHEY_SIMPLEX, 2,(165,42,42),5)
# 绘制中文
# 创建一个可以在给定图像上绘图的对象
img_np= Image.fromarray(img)
draw = ImageDraw.Draw(img_np)
# 字体的格式
fontStyle = ImageFont.truetype("simsun.ttc", size=64 ,encoding="utf-8")
# 绘制文本
draw.text((10, 250),"图形图像处理",(192, 192, 192),font=fontStyle)
img = np.array(img_np)
cv2.imshow("cv2.putText",img)
cv2.waitKey(0)
cv2.destroyAllWindows()
